package top.wanzc.java.basic.sort;

import java.util.Arrays;
/**
 * ��������
 * @author zhengchong.wan
 *
 */
public class InsertSortDemo {
	
	public static void main(String[] args) {
		int a[] = {49, 38, 65, 97, 76, 13, 27, 49, 0, 0, 0, 0, 0};
		// �ٶ�a�ĳ���Ϊ8
		sort(a, 8);
		System.out.println(Arrays.toString(a));
	}
	
	private static void sort(int[] a, int n) {
		for (int i = 1; i <= n-1; i++) {
			int temp = a[i];
			int j;
			for (j = i - 1; j >= 0; j--) {
				if (a[j] > temp) {
					a [j + 1] = a[j];
				} else {
					break;
				}
			}
			a[j + 1] = temp;
		}
	}

}
